package inputStream;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 功能描述：输入数字到数组中
 *
 * @Author: lwg
 * @Date: 2021/3/29 21:43
 */
public class demo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一行数字,中间用空格隔开");
        String[] numbers = scanner.nextLine().trim().split("\\s+");  //读取一行字符串,并移除中间的空格
        int[] nums = new int[numbers.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i]=Integer.parseInt(numbers[i]); //将字符串转换成整数型
        }

        System.out.println("输入的数字为: "+Arrays.toString(nums));
        System.out.println(numbers.length);

    }
}
